home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: automatic charrs
- Date: 24 Feb 1996 17:11:55 GMT
- Organization: systems hk
- Message-ID: <4gngsr$8jr@maureen.teleport.com>
- References: <4glp29$dsh@d2.tufts.edu>
- NNTP-Posting-Host: ip-pdx13-51.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- rdorich@emerald.tufts.edu (Roberto Dorich) wrote:
- >Could someone enlighten me, and tell me why the following program runs
- >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
- >
- >#include <stdio.h>
- >char *b() { return "Hello";}
- >main() {
- > char *a=b();
- > a[0]='X';
- > printf("--> %s\n",a);
- >}
- [snip]
- Roberto
- Since a is a pointer to a character, and is initialized to the
- return value of b(), it contains a ptr to the string "Hello"
- which may or may not be in transitory or read-only memory,
- depending on the environment. Therefore, setting the first character
- to 'X' may generate an access violation.
- Yours, Geoff Houck
-
-
-